New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sorting by sub-aggregation is broken in terms agg #4643
Comments
…regator to enable access to metrics values without creating buckets fixes: #4643
fixed |
…regator to enable access to metrics values without creating buckets fixes: elastic#4643
Hi all, { While this code does order by the sums of that field, it is omitting many terms that would have even greater sums. It is only after I increase the size parameter to something pretty high (10 --> 1000 in this case), does it then 'catch' the terms with the largest summations of field "impression". Is there other code I should be using for this or is this a bug? Thanks!
|
Hi Trev, You probably want to increase the Here's the relevant section in the docs: http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-aggregations-bucket-terms-aggregation.html#_size_amp_shard_size – Alex |
Excellent! I'll give that a whirl. Thanks for the help (and fast response)!
|
I'm using 1.0.0-RC1 and this doesn't appear to be working correctly for me for a metric sub-aggregation. If I use the following query:
It appears to be sorted in 'asc' mode, and changing 'desc' to 'asc' produces the same results. Other than that the query does appear to work successfully and returns the expected sort of data in the buckets. Changing the order key from 'totalAmount' to '_term' works as expected, and 'asc' and 'desc' show different results. I've looked at the code for 1.0.0-RC1 and the above changes do appear to be in, was it working for you on RC1 Trev? |
@benatwork99 I just indexed a few documents that fit the aggs you have above, and it seem to work as expected. Are you sure you're running it on RC1? here's what I ran (save it to a file curl -XDELETE 'http://localhost:9200/idx?pretty'; echo;
for i in {1..3}
do
curl -XPOST 'http://localhost:9200/idx/type&pretty' -d '{
"name" : {
"field" : "val1"
},
"amount" : '$i'
}'; echo;
done
for i in {1..2}
do
curl -XPOST 'http://localhost:9200/idx/type&pretty' -d '{
"name" : {
"field" : "val2"
},
"amount" : '$i'
}'; echo;
done
sleep 3s; ehco;
dir=$1
echo 'executing search ('$dir')';
curl -XGET 'http://localhost:9200/idx/_search?search_type=count&pretty' -d '{
"aggs": {
"fieldValues": {
"terms": {
"field": "name.field",
"order": {
"totalAmount": "'$dir'"
}
},
"aggs": {
"totalAmount": {
"sum": {
"field": "amount"
}
}
}
}
}
}'; echo; desc order : |
Thank you very much for the detailed reply uboness. If I download the vanilla RC1 distribution and run your query against it, I can confirm that it works as intended. Our version is part of a larger build and configuration process, it's definitely RC1 but there's obviously something else - distribution or configuration - affecting it. I'm looking in to this now trying to understand what's different, will post back as soon as I can figure it out, and hopefully this won't have been just a waste of time for you! |
@benatwork99 ok, cool, keep us posted (and it's definitely not a waste of our time... we're here to make it work :)) |
Aha! Ok turned out our test and dev setups use a single shard - setting
in elasticsearch.yml. With this set to 1, I see ordering by the metric sub aggregate always sorting in ascending order! Leaving it blank (or setting it to 2 or higher) means that the descending order works as expected. So, I think that's a bug. At least I wasn't doing something daft ;) Do you want me to create a separate issue on it? |
@benatwork99 yep.. indeed a bug... opened an issue for it, will be fixed shortly. Thanks! (see.. no waste of time :)) |
@uboness I'm seeing an issue with sorting by sub-agg when two of the values equal each other.. for example: Doc 1 and 2 work fine but with Doc 3 it will throw NPE. Mapping
Doc 1
Doc 2
Doc 3
Agg
Result
|
Terms aggregations enables sorting by sub metric aggregation, a la:
unfortunately, that got broken along the way.
The fix will be mostly based on #4472
thx @alexbrasetvik
The text was updated successfully, but these errors were encountered: